package com.briup.web.controller;

import com.briup.bean.Shop;
import com.briup.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class ListController {
    @Autowired
    private IShopService shopService;

    @GetMapping(value = {"/toList"})
    public String toList(HttpServletRequest request, Model model){
        List<Shop> shopList = shopService.findByCategory(Long.valueOf(request.getParameter("categoryId")));
        model.addAttribute("shopList",shopList);
        return "list";
    }

    @GetMapping(value = {"/searchShop"})
    public String searchShop(Model model ,String shopName){
        List<Shop> shopList = shopService.searchShop(shopName);
        model.addAttribute("shopList",shopList);
        return "list";
    }
}
